package com.minivision.sdktestdemo.utils;

import android.app.Activity;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.EditText;

import com.minivision.sdktestdemo.R;
import com.minivision.sdktestdemo.ui.view.PopClickItemFactory;

/**
 * Created by devtang on 2016/5/14.
 */
public class AlertDialogUtils {

    private static boolean sIsAllDeleted;

    private static AlertDialog sDlg;

    private static View sView;

    public static void release() {
        sDlg = null;
        sView = null;
    }

    public static AlertDialog getDeleteDialog(Activity context, final PopClickItemFactory.OnDeleteListener listener, String content) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.alertdialogTheme);
        builder.setTitle(content);
        builder.setMultiChoiceItems(new String[]{"同时删除本地文件"}, new boolean[]{false}, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                sIsAllDeleted = isChecked;
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                sIsAllDeleted = false;
                sDlg.dismiss();
            }
        });
        builder.setPositiveButton("删除", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                sDlg.dismiss();
                listener.onDelete(sIsAllDeleted);
            }
        });
        sDlg = builder.create();
        return sDlg;
    }

    public static AlertDialog getChangedDialog(Activity context, final PopClickItemFactory.OnMusicChangedListener listener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.alertdialogTheme);
        builder.setTitle("修改歌曲信息");
        sView = context.getLayoutInflater().inflate(R.layout.layout_music_change, null);
        builder.setView(sView);
        ((EditText) sView.findViewById(R.id.edit_music)).setText(listener.getBean().getmMusicName());
        ((EditText) sView.findViewById(R.id.edit_singer)).setText(listener.getBean().getmSingerName());
        ((EditText) sView.findViewById(R.id.edit_album)).setText(listener.getBean().getmAlbumName());
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                sDlg.dismiss();
            }
        });
        builder.setPositiveButton("提交", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                sDlg.dismiss();
                listener.getBean().setmMusicName(((EditText) sView.findViewById(R.id.edit_music)).getText().toString());
                listener.getBean().setmSingerName(((EditText) sView.findViewById(R.id.edit_singer)).getText().toString());
                listener.getBean().setmAlbumName(((EditText) sView.findViewById(R.id.edit_album)).getText().toString());
                listener.onChanged();
            }
        });
        sDlg = builder.create();
        return sDlg;
    }

}
